package dht.storage;

import java.io.IOException;
import java.util.HashMap;
import java.util.Vector;

import dht.entity.GlobalVariables;
import dht.tool.FileGenerator;

public class FakeDirectory {

	public HashMap<Integer, Vector<String>> vnodeId2FileNames;
	public HashMap<String, Integer> fileName2BlockNum;

	public FakeDirectory() {
		this.vnodeId2FileNames = new HashMap<Integer, Vector<String>>();
		for (int i = 0; i < GlobalVariables.ringLength; ++i) {
			vnodeId2FileNames.put(i, new Vector<String>());
		}
	}

	public void initialize() {
		int fileNum = GlobalVariables.fakeFileNumber;
		try {
			fileName2BlockNum = FileGenerator.generate(fileNum, 16);
		} catch (IOException e) {
			e.printStackTrace();
		}
		for (String fileName : fileName2BlockNum.keySet()) {
			vnodeId2FileNames.get(PathUtils.getVnodeId(fileName)).add(fileName);
		}
	}

	public Vector<String> getFileNamesByVnodeId(int vnodeId) {
		return vnodeId2FileNames.get(vnodeId);
	}

}
